<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <div id="app">
            <p>
                <input type="text" v-model='userinfo.firstname' placeholder="姓">
            </p>
            <p>
                <input type="text" v-model='userinfo.lastname' placeholder="名">
            </p>
            <p>
                <input type="text" v-model='userinfo.fullname' placeholder="全名">
            </p>
        </div>

    </div>


    <script>

        var app = new Vue({
            el: '#app',
            data: {
                userinfo: {
                    firstname: '',
                    lastname: '',
                    fullname: ''
                }
            },
            // watch的深度监听
            watch:{
                // 先写深度监听的对象
               userinfo:{
                //     处理函数
                   handler(val) {
                        console.log('val',val)
                        this.userinfo.fullname = val.firstname +' ' +val.lastname
                   },
                //    立即监听
                  immediate:true,
                //    深度监听参数
                deep:true

               }
            }
        })

        console.log('app', app)

    </script>
</body>

</html>